package com.zhuss.outer.processor;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.SearchKeyWordBo;
import com.zhuss.bean.bo.outer.outer.SearchOuterBo;
import com.zhuss.bean.bo.outer.outer.wechat.ListOuterBo;
import com.zhuss.bean.vo.DetailKeyWordVo;
import com.zhuss.bean.vo.outer.outer.DetailOuterVo;
import com.zhuss.bean.vo.outer.outer.ListOuterVo;
import com.zhuss.outer.db.dao.ext.OuterDao;
import com.zhuss.outer.db.entity.Outer;
import com.zhuss.common.PageVo;
import com.zhuss.exception.ExceptionCode;
import com.zhuss.exception.WpsException;


/**
 * 查询外包消息 processor
 * @Author: zhushanshuo
 * @Date: 2019/9/24 19:54
 */
@Component("outerRead")
public class OuterRead {
	
	@Autowired
	private OuterDao outerDao;
	
	/**
	 * 外包消息 
	 * @return
	 */
	public Object listOuterId(Integer area) {
		List<Outer> outerList = outerDao.listAll(area);
		List<Long> result = new ArrayList<>();
		transferListId(outerList, result);
		return result;
	}
	
	/**
	 * keyWord
	 * @param bo
	 * @return
	 */
	public PageVo<DetailKeyWordVo> keyWord(SearchKeyWordBo bo) {
		PageVo<DetailKeyWordVo> result = new PageVo<DetailKeyWordVo>();
		List<DetailKeyWordVo> list = new ArrayList<DetailKeyWordVo>();
		list = outerDao.keyWord(bo);
		Integer count = outerDao.countKeyWord(bo);
		result.setPageNum(bo.getPageNum());
		result.setPageSize(bo.getPageSize());
		result.setTotal(count);
		result.setItems(list);
		return result;
	}
	
	
	
	/**
	 * 外包消息列表
	 * @param bo
	 * @return
	 */
	public Object listOuter(ListOuterBo bo) {
		PageVo<DetailOuterVo> result = new PageVo<DetailOuterVo>();
		List<DetailOuterVo> list = new ArrayList<DetailOuterVo>();
		list = outerDao.listOuter(bo);
		Integer count = outerDao.countOuterList(bo);
		result.setPageNum(bo.getPageNum());
		result.setPageSize(bo.getPageSize());
		result.setTotal(count);
		result.setItems(list);
		return result;
	}
	
	private void transferListId(List<Outer> outerList, List<Long> result) {
		for (Outer item : outerList) {
			result.add(item.getOuterId());
		}
	}

	/**
	 * 外包消息列表
	 * @param bo
	 * @return
	 */
	public Object list(SearchOuterBo bo) {
		PageVo<ListOuterVo> result = new PageVo<ListOuterVo>();
        result.setPageNum(bo.getPageNum());
        result.setPageSize(bo.getPageSize());
        result.setItems(outerDao.list(bo));
        result.setTotal(outerDao.countList(bo));
		return result;
	}
	
	/**
	 * 外包消息详情
	 * @param outerId
	 * @return
	 * @throws WpsException
	 */
	public Object detail(Long outerId) throws WpsException {
		Object result = outerDao.detail(outerId);
		if (result == null) {
			throw new WpsException(ExceptionCode.数据不存在);
		}
		return result;
	}
	
	

}
